import request from '@/utils/request'

export function areaImportCheck (file) {
  let fd = new FormData()
  fd.append('import', file)
  return request({
    url: '/area/import/check',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}

export function schoolImportCheck (file) {
  let fd = new FormData()
  fd.append('import', file)
  return request({
    url: '/school/import/check',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}

export function physicalImportCheck (file, date, schoolId) {
  let fd = new FormData()
  let fdate = new Date(Date.parse(date))
  let year = fdate.getFullYear()
  let month = fdate.getMonth() + 1
  if (month < 10) {
    month = '0' + month
  }
  let day = fdate.getDate()
  if (day < 10) {
    day = '0' + day
  }
  fd.append('import', file)
  fd.append('measureDate', year + '-' + month + '-' + day)
  fd.append('schoolId', schoolId)
  return request({
    url: '/physical/import/check',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}

export function physicalImportSubmit (file, date, schoolId) {
  let fd = new FormData()
  let fdate = new Date(Date.parse(date))
  let year = fdate.getFullYear()
  let month = fdate.getMonth() + 1
  if (month < 10) {
    month = '0' + month
  }
  let day = fdate.getDate()
  if (day < 10) {
    day = '0' + day
  }
  fd.append('import', file)
  fd.append('measureDate', year + '-' + month + '-' + day)
  fd.append('schoolId', schoolId)
  return request({
    url: '/physical/import/submit',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}

export function areaImport (file) {
  let fd = new FormData()
  fd.append('import', file)
  return request({
    url: '/area/import/submit',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}

export function schoolImport (file) {
  let fd = new FormData()
  fd.append('import', file)
  return request({
    url: '/school/import/submit',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: fd
  })
}
